﻿using Futajma.MigrationStudio.DataDefinition;
using Futajma.MigrationStudio.CommonLib.TreeDebug;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Futajma.MigrationStudio.CommonLib.TreeOperations
{
    public class CleanUp
    {
        public static void CleanUpTree(TreeNodeDebugger treeNodeDebugger, TreeView sourceTree)
        {
            foreach (TreeNode node in sourceTree.Nodes)
            {
                CheckAndCleanUpDisabledItems(treeNodeDebugger, node);
            }
        }

        private static void CheckAndCleanUpDisabledItems(TreeNodeDebugger treeNodeDebugger, TreeNode node)
        {
            var targetNode = treeNodeDebugger[node];

            if (targetNode == null)
            {
                var dataNode = node.Tag as DataNode;

                dataNode.NodeDisabled = false;
            }

            foreach (TreeNode child in node.Nodes)
            {
                CheckAndCleanUpDisabledItems(treeNodeDebugger, child);
            }
        }
    }
}
